const Koa = require("koa");
const KoaRouter = require("koa-router");
const sendFile = require("koa-sendfile");
const path = require("path");
const { OnePxGIF } = require("./utils/miniGif");
const { generateIdNumber } = require("./utils/idGenerate");
const app = new Koa();
const router = new KoaRouter();

// Routes
router.get(`/`, async (ctx) => {
  await sendFile(ctx, path.join(__dirname, "index.html"));
});

router.get(`/api/image/miniGIF`, async (ctx) => {
  let color = ctx.query["color"];
  let gifInstance = new OnePxGIF();
  let result = gifInstance.generateBase64(color);
  ctx.response.body = result;
});


router.get(`/api/idNumber/generate`, async (ctx) => {
  let result = generateIdNumber();
  ctx.response.body = result;
});


app.use(router.allowedMethods()).use(router.routes());

app.listen(9000, () => {
  console.log(`Server start on http://localhost:9000`);
});
